package test;

import java.util.Arrays;

/**
 * @author 郝文雪
 * @date 2022/7/21 20:28
 * @Description Test
 */
public class sort {
    public static void main(String[] args) {
        int[] arr={3,2,4,1,6};
        quickSort(arr,0,arr.length-1);
        System.out.println(Arrays.toString(arr));
    }
    private static void quickSort(int[] arr,int l,int r){
        if(l>=r) return;
        int partition=quickSortInternal(arr,l,r);
        quickSortInternal(arr,l,partition-1);
        quickSortInternal(arr,partition+1,r);
    }

    private static int quickSortInternal(int[] arr, int l, int r) {
        int v=arr[l];
        int j=l;
        for(int i=l+1;i<=r;i++){
            if(arr[i]<v){
                swap(arr,j+1,i);
                j++;
            }
        }

        swap(arr,j,l);
        return j;
    }

    private static void swap(int[] arr, int x, int y) {
        int temp=arr[x];
        arr[x]=arr[y];
        arr[y]=temp;
    }


}
